package com.himore.api.web.controller.modules;

import java.util.List;

import com.himore.api.common.annotation.Log;
import com.himore.api.common.core.controller.BaseController;
import com.himore.api.common.core.domain.AjaxResult;
import com.himore.api.common.core.domain.entity.SysUser;
import com.himore.api.common.core.page.TableDataInfo;
import com.himore.api.common.enums.BusinessType;
import com.himore.api.common.utils.SecurityUtils;
import com.himore.api.common.utils.poi.ExcelUtil;
import com.himore.api.web.enums.AwardsTypeEnum;
import com.himore.api.web.model.TSelectedAwards;
import com.himore.api.web.service.ITSelectedAwardsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 我的奖品信息Controller
 * 
 * @author ruoyi
 * @date 2021-01-14
 */
@RestController
@RequestMapping("/system/selected/awards")
public class TSelectedAwardsController extends BaseController
{
    @Autowired
    private ITSelectedAwardsService tSelectedAwardsService;

    /**
     * 查询我的奖品信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TSelectedAwards tSelectedAwards){
        startPage();
        SysUser  user = SecurityUtils.getLoginUser().getUser();
        tSelectedAwards.setUserId(user.getUserId());
        List<TSelectedAwards> list = tSelectedAwardsService.selectTSelectedAwardsList(tSelectedAwards);
        return getDataTable(list);
    }

    /**
     * 查询我的奖品信息列表
     */
    @GetMapping("/myAwardlist")
    public TableDataInfo myAwardlist(TSelectedAwards tSelectedAwards){
        startPage();
        SysUser  user = SecurityUtils.getLoginUser().getUser();
        tSelectedAwards.setUserId(user.getUserId());
        tSelectedAwards.setAwardType(AwardsTypeEnum.ROTARY_TABLE.getValue());
        List<TSelectedAwards> list = tSelectedAwardsService.selectTSelectedAwardsList(tSelectedAwards);
        return getDataTable(list);
    }

    /**
     * 导出我的奖品信息列表
     */
    @Log(title = "我的奖品信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSelectedAwards tSelectedAwards){
        List<TSelectedAwards> list = tSelectedAwardsService.selectTSelectedAwardsList(tSelectedAwards);
        ExcelUtil<TSelectedAwards> util = new ExcelUtil<TSelectedAwards>(TSelectedAwards.class);
        return util.exportExcel(list, "awards");
    }

    /**
     * 获取我的奖品信息详细信息
     */
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId){
        return AjaxResult.success(tSelectedAwardsService.selectTSelectedAwardsById(recordId));
    }

    /**
     * 新增我的奖品信息
     */
    @Log(title = "我的奖品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSelectedAwards tSelectedAwards){
        return toAjax(tSelectedAwardsService.insertTSelectedAwards(tSelectedAwards));
    }

    /**
     * 修改我的奖品信息
     */
    @Log(title = "我的奖品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSelectedAwards tSelectedAwards){
        return toAjax(tSelectedAwardsService.updateTSelectedAwards(tSelectedAwards));
    }

    /**
     * 删除我的奖品信息
     */
    @Log(title = "我的奖品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds){
        return toAjax(tSelectedAwardsService.deleteTSelectedAwardsByIds(recordIds));
    }
}
